#pragma once

#include	<Singleton.h>
#include	<functional>
#include	<map>
#include	<string>

class Balancer : public ISingleton<Balancer> {
public:
	struct Device {
		int type;
		uint64_t connect;
		std::string ip;
		int port;
		int capacity;
	};

public:
	Balancer() = default;
	virtual ~Balancer() = default;

	void Add(uint64_t connect, int type, const std::string & ip, int port);
	void Del(uint64_t connect);
	void Inc(uint64_t connect);
	void Dec(uint64_t connect);

	Device * Peek(int type);
	void Foreach(int type, std::function<void(Device *)> processor);

private:
	std::map<uint64_t, Device *> _devices;
};